//幂的线性迭代
function expt(b,n){
    return currentExpt(b,n);
    function currentExpt(b,n,product=1){
        if(n===0) return product;
        return currentExpt(b,n-1,b*product);
    }
}
const b=10
const n=2
console.log(expt(b,n))
//斐波那契数列的树型迭代
function fb(m,result1 =1,result2 = 1){
    if(m <= 2) return result2;    
    return fb(m-1,result2,result1 + result2);
}
const m=10
console.log(fb(m))
//提高时间效率

function expt2(b1,n1){
    return currentExpt(b1,n1);
    function currentExpt(b1,n1,product=1){
        if(n1===0) return product;
        if(n1%2==0){
            return currentExpt(b1,n1/2-1,b1*product)
        }else{
            return currentExpt(b1,n1-1,b1*product);
        }
        
    }
}
const n1=4
const b1=10
console.log(expt2(b1,n1))
